﻿using EFCore.Dbfirst.Models;

using Microsoft.EntityFrameworkCore;
using MSACommerce.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MSACommerce.Service
{
    /// <summary>
    /// 用户服务类
    /// </summary>
    public class UserService : BaseService, IUserService
    {
        public UserService(DbContext context)
         : base(context)
        {
        }

        public void AddUser(Users account)
        {
            var data = new Users()
            {
                Age = account.Age,
                DateTime = DateTime.Now,
                Name = account.Name,
                Pwd = account.Pwd
            };
            this.Insert<Users>(data);
            this.Commit();
        }

        /// <summary>
        /// 获取账号
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public Users GetAccountMsg(string account)
        {
            var data = this.FindString<Users>(account);
            return data;
        }

        public void UpdateLoginTime(DateTime time, int id)
        {
            var data = this.Find<Users>(id);
            data.DateTime = time;
            this.Update<Users>(data);
            this.Commit();
        }
    }
}